<template>
    <div id="wrapper">
		<!-- <el-row style="margin-bottom:20px"> -->
			<el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
				<el-tab-pane label="代码规范检查" name="0">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'次数'"
								:title="common.titles[5]"
								:num="String(labelsData.code_style_check)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub "
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'平均'"
								:title="common.titles[9]"
								:num="String(labelsData.avg_style_errors)"
								:sub="common.subs[3]"
								:to_sub="common.avg"
								:cls="common.danger"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
						<info_label
							:type="common.type2"
							:title="common.titles[38]"
							:num="String(labelsData.style_count)"
							:sub="common.subs[0]"
							:to_sub="common.to_sub"
							:cls="common.success"
						></info_label>
					</el-col>
						<el-col :xs="24" :sm="24" :lg="6">							
							<info_label
								:type="'次数'"
								:title="'每Patch平均检查次数'"
								:num="String(labelsData.style_check_count)"
								:to_sub="common.to_sub "
								:sub="common.subs[0]"
								:cls="common.success"
							></info_label>							
						</el-col>
          			</el-row>
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="checkpatch检查" 															
								unit="percent"
								:number="labelsData.checkpatch_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.checkpatch_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>				
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="clint检查" 														
								unit="percent"
								:number="labelsData.clint_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.clint_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>							
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="cpplint检查" 																
								unit="percent"
								:number="labelsData.cpplint_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.cpplint_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>							
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="checkstyle检查" 																
								unit="percent"
								:number="labelsData.checkstyle_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.checkstyle_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>
						</el-col>
					</el-row>

						<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>规范检查错误排名</span>
							</div>
							<div>
								<ve-bar
									:data="topChartData1"
									:settings="chartSettings"
									:extend="topExtend"
									:colors="colors"
									:legend-visible="true"
									ref="vline0"
									></ve-bar>
							</div>
						</el-card>						

						<!-- <el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>规范检查错误趋势</span>
							</div>
							<div>
								<ve-line
								ref="lline0"
								:data="codeChartData2"
								:settings="codeChartSettings"
								:colors="colors"
								:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>						 -->

						<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>代码规范检查效率趋势</span>
							</div>
							<div>
								<ve-line
									ref="jline0"
									:data="efficiencyData1"
									:settings="setEfficiency"
									:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>

						<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix" style="vertical-align:middle">
								<div style="float: left; padding: 10px 0">平均检查通过趋势</div>
								<el-radio-group v-model="passTrend" style="float: right; padding: 3px 0" size="mini">
									<el-radio-button label="checkstyle指标"></el-radio-button>
									<el-radio-button label="cpplint指标"></el-radio-button>
									<el-radio-button label="clint指标"></el-radio-button>
									<el-radio-button label="checkpatch指标"></el-radio-button>
								</el-radio-group>
							</div>
							<div v-if="passTrend === 'checkstyle指标'">
								<ve-line
									ref="tline0"
									:data="checkstyle_data"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
							<div v-else-if="passTrend === 'cpplint指标'">
								<ve-line
									ref="tline1"
									:data="cpplintstyle_data"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
							<div v-else-if="passTrend === 'clint指标'">
								<ve-line
									ref="tline2"
									:data="clintstyle_data"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
							<div v-else>
								<ve-line
									ref="tline3"
									:data="checkpatchstyle_data"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>
				</el-tab-pane>
				<el-tab-pane label="代码静态检查" name="1">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'次数'"
								:title="common.titles[4]"
								:num="String(labelsData.code_static_check)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'个数'"
								:title="common.titles[13]"
								:num="String(labelsData.avg_static_errors)"
								:sub="common.subs[3]"
								:to_sub="common.avg"
								:cls="common.danger"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type2"
								:title="common.titles[38]"
								:num="String(labelsData.static_count)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'次数'"
								:title="'每Patch平均检查次数'"
								:num="String(labelsData.static_check_count)"
								:to_sub="common.to_sub "
								:sub="common.subs[0]"
								:cls="common.success"
							></info_label>							
						</el-col>				
					</el-row>
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								type="高"
								title="Coverity错误数"
								:num="String(labelsData.coverity_high)"
								:sub="common.subs[3]"
								:to_sub="common.type2"
								:cls="common.danger"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								type="中"
								title="Coverity错误数"
								:num="String(labelsData.coverity_medium)"
								:sub="common.subs[3]"
								:to_sub="common.type2"
								:cls="common.danger"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								type="低"
								title="Coverity错误数"
								:num="String(labelsData.coverity_low)"
								:sub="common.subs[3]"
								:to_sub="common.type2"
								:cls="common.danger"
							></info_label>
						</el-col>
						
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(coverity_high_err_density, [false, 20], 'frequency', common.titles[41], common.titles[42])"
								:to_sub="common.avg + ' (目标<=20)'"
								:sub="common.subs[3]"
								:cls="common.danger"
							></info_label_compare>
						</el-col>
					</el-row>
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(coverity_medium_err_density, [false, 20], 'frequency', common.titles[41], common.titles[43])"
								:to_sub="common.avg + ' (目标<=20)'"
								:sub="common.subs[3]"
								:cls="common.danger"
							></info_label_compare>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(coverity_low_err_density, [false, 20], 'frequency', common.titles[41], common.titles[44])"
								:to_sub="common.avg + ' (目标<=20)'"
								:sub="common.subs[3]"
								:cls="common.danger"
							></info_label_compare>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="coverity检查" 								 								
								unit="percent"
								:number="labelsData.coverity_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.coverity_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="findbugs检查" 													
								unit="percent"
								:number="labelsData.findbugs_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.findbugs_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>
						</el-col>
					</el-row>
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<tag 
								title="pclint检查" 								 								
								unit="percent"
								:number="labelsData.pclint_pass_rate"
								numberName="通过率"
								:double="{value: labelsData.pclint_pass_count, numberName: '通过次数', unit: '次'}"
								></tag>							
						</el-col>						
					</el-row>
					<!-- 排名 -->
					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>静态检查错误排名</span>
							</div>
							<div>
								<ve-bar
									:data="topChartData2"
									:settings="chartSettings"
									:extend="topExtend"
									:colors="colors"
									:legend-visible="true"
									ref="vline1"
									></ve-bar>
							</div>
						</el-card>

						<!-- 趋势 -->
						<el-card class="box-card m-b marT" shadow="never">
								<div slot="header" class="clearfix">
									<span>静态检查错误趋势</span>
								</div>
								<div>
									<ve-line
										:data="codeChartData"
										:settings="codeChartSettings"
										:colors="colors"
										ref="lline1"
										:data-zoom="dataZoom"></ve-line>
								</div>
							</el-card>

						<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>代码静态检查效率趋势</span>
							</div>
							<div>
								<ve-line
									ref="jline1"
									:data="efficiencyData2"
									:settings="setEfficiency"
									:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>
						<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>平均检查通过趋势</span>
							</div>
							<div>
								<ve-line
									ref="zline1"
									:data="quality_trend_data"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>
				</el-tab-pane>
				<el-tab-pane label="代码质量检查" name="2">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'次数'"
								:title="common.titles[6]"
								:num="String(labelsData.code_quality_check)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>

						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'平均'"
								:title="common.titles[11]"
								:num="String(labelsData.avg_simain_dupliate)"
								:sub="'行'"
								:to_sub="common.avg"
								:cls="common.danger"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(duplicateRate, [false, 5], 'percent', common.titles[40], common.avg)"
								:to_sub="common.type3 + ' (目标<=5%)'"
								:sub="common.subs[7]"
								:cls="common.success"
							></info_label_compare>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="common.type2"
								:title="common.titles[38]"
								:num="String(labelsData.quality_count)"
								:sub="common.subs[0]"
								:to_sub="common.to_sub"
								:cls="common.success"
							></info_label>
						</el-col>
					</el-row>
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<!-- <info_label_compare
								:params="generate_label_params(labelsData.avg_complexity, [true, kpi.avg_complexity], 'frequency', common.titles[10], common.avg)"
								:to_sub="common.avg + ' (目标<'+kpi.avg_complexity+')'"
								:cls="common.success">
							</info_label_compare> -->
							<LabelGrid
							:label_info="deptlableinfo.quan"
							:label_data="getFix(labelsData.avg_complexity)"
							:label_import="'small'"
							:label_avg="standardKPI.avg_complexity"
							:label_now="labelsData.avg_complexity"
							:label_good="kpi.avg_complexity"
							:label_precent="'num'"
							:nessary="true">
							</LabelGrid>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(labelsData.exceed_complexity_num, [false, 20], 'frequency', common.titles[31], common.type2)"
								:to_sub="common.to_sub + ' (目标<=18)'"
								:sub="common.subs[3]"
								:cls="common.danger"
							></info_label_compare>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label_compare
								:params="generate_label_params(labelsData.exceed_complexity_rate, [true, 80], 'percent', common.titles[32], common.avg)"
								:to_sub="common.type3 + ' (目标>=80%)'"
								:sub="common.subs[7]"
								:cls="common.danger"
							></info_label_compare>
						</el-col>
					</el-row>

					<el-card class="box-card m-b marT" shadow="never">
						<div slot="header" class="clearfix">
							<span>代码重复行数排名</span>
						</div>
						<div>
							<ve-bar
								:data="topChartData3"
								:settings="chartSettings"
								:extend="topExtend"
								:colors="colors"
								:legend-visible="true"
								ref="cline2"
								></ve-bar>
						</div>
					</el-card>
					<!-- 排名 -->
					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>圈复杂度排名</span>
							</div>
							<div>
								<ve-bar
									:data="topChartData5"
									:settings="chartSettings"
									:extend="topExtend"
									:legend-visible="true"
									ref="vline2"
									></ve-bar>
							</div>
					</el-card>
					<!-- 趋势 -->
					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>圈复杂度趋势</span>
							</div>
							<div>
								<ve-line
									ref="lline2"
									:data="codeChartData5"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
					</el-card>

					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>代码重复行数趋势</span>
							</div>
							<div>
								<ve-line
									ref="eline2"
									:data="codeChartData4"
									:settings="codeChartSettings"
									:colors="colors"
									:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>

					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>代码质量检查效率趋势</span>
							</div>
							<div>
								<ve-line
									ref="jline2"
									:data="efficiencyData3"
									:settings="setEfficiency"
									:data-zoom="dataZoom"></ve-line>
							</div>
						</el-card>

				</el-tab-pane>
				<el-tab-pane label="Git log检查" name="3">
					<el-row :gutter="30">
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'次数'"
								:title="common.titles[23]"
								:num="String(labelsData.git_log_check)"
								:to_sub="common.to_sub "
								:sub="common.subs[0]"
								:cls="common.success"
							></info_label>
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<info_label
								:type="'次数'"
								:title="'每Patch平均检查次数'"
								:num="String(labelsData.git_check_count)"
								:to_sub="common.to_sub "
								:sub="common.subs[0]"
								:cls="common.success"
							></info_label>							
						</el-col>
						<el-col :xs="24" :sm="24" :lg="6">
							<LabelGrid
							:label_info="deptlableinfo.rate"
							:label_data="getPrecent(labelsData.git_pass_rate)"
							:label_import="'big'"
							:label_avg="standardKPI.git_log_pass_rate"
							:label_now="labelsData.git_pass_rate"
							:label_good="kpi.git_log_pass_rate"
							:label_precent="'precent'"
							:nessary="true">
							</LabelGrid>
						</el-col>

					</el-row>
					<!-- 排名 -->
					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>git log检查通过率排名</span>
							</div>
							<div>
								<ve-bar
									:data="topChartData4"
									:settings="chartSettings"
									:extend="topExtend"
									:legend-visible="true"
									ref="vline3"
									></ve-bar>
							</div>
					</el-card>
					<!-- 趋势 -->
					<el-card class="box-card m-b marT" shadow="never">
							<div slot="header" class="clearfix">
								<span>git log检查通过率趋势</span>
							</div>
							<div>
								<ve-line
									ref="lline3"
									:data="codeChartData3"
									:settings="codeChartSettings"
									:data-zoom="dataZoom"></ve-line>
							</div>
					</el-card>

				</el-tab-pane>
			</el-tabs>

			<!-- <el-tabs class="bgColor marT" type="border-card" v-model="activeName2">
				<el-tab-pane name="0" label="规范检查错误(平均)">
						<ve-bar
						:data="topChartData1"
						:settings="chartSettings"
						:extend="topExtend"
						:colors="colors"
						:legend-visible="true"
						ref="vline0"
						></ve-bar>
				</el-tab-pane>
				<el-tab-pane name="1" label="静态检查错误(平均)">
						<ve-bar
						:data="topChartData2"
						:settings="chartSettings"
						:extend="topExtend"
						:colors="colors"
						:legend-visible="true"
						ref="vline1"
						></ve-bar>
				</el-tab-pane>
				<el-tab-pane name="2" label="代码重复行数(平均)">
						<ve-bar
						:data="topChartData3"
						:settings="chartSettings"
						:extend="topExtend"
						:colors="colors"
						:legend-visible="true"
						ref="vline2"
						></ve-bar>
				</el-tab-pane>
				<el-tab-pane name="3" label="git log检查通过率">
						<ve-bar
						:data="topChartData4"
						:settings="chartSettings"
						:extend="topExtend"
						:legend-visible="true"
						ref="vline3"
						></ve-bar>
				</el-tab-pane>
				<el-tab-pane name="4" label="圈复杂度(平均)">
						<ve-bar
						:data="topChartData5"
						:settings="chartSettings"
						:extend="topExtend"
						:legend-visible="true"
						ref="vline4"
						></ve-bar>
				</el-tab-pane>
			</el-tabs> -->

			<!-- <el-tabs v-model="activeNameError" class="bgColor marT" type="border-card">
				<el-tab-pane label="静态检查错误数(平均)" name="0">
					<ve-line
							:data="codeChartData"
							:settings="codeChartSettings"
							:colors="colors"
							ref="eline0"
							:data-zoom="dataZoom"></ve-line>
				</el-tab-pane>
				<el-tab-pane label="规范检查错误数(平均)" name="1">
					<ve-line
					 		ref="eline1"
							:data="codeChartData2"
							:settings="codeChartSettings"
							:colors="colors"
							:data-zoom="dataZoom"></ve-line>
				</el-tab-pane>
				<el-tab-pane label="git log通过率" name="2">
					<ve-line
					 		ref="eline2"
							:data="codeChartData3"
							:settings="codeChartSettings"
							:colors="colors"
							:data-zoom="dataZoom"></ve-line>
				</el-tab-pane>
				<el-tab-pane label="代码重复行数(平均)" name="3">
					<ve-line
					 		ref="eline3"
							:data="codeChartData4"
							:settings="codeChartSettings"
							:colors="colors"
							:data-zoom="dataZoom"></ve-line>
				</el-tab-pane>
				<el-tab-pane label="圈复杂度(平均)" name="4">
					<ve-line
					 		ref="eline4"
							:data="codeChartData5"
							:settings="codeChartSettings"
							:data-zoom="dataZoom"></ve-line>
				</el-tab-pane>
			</el-tabs> -->

        <!-- <el-card class="box-card m-b mart" shadow="never" style="margin-bottom:20px">
					<div slot="header" class="clearfix">
						<span>构建效率趋势(平均时长)</span>
					</div>
					<div>
						<ve-line
							:data="codeChartData"
							:settings="codeChartSettings"
							:data-empty="dataEmpty"
							:data-zoom="dataZoom"
						></ve-line>
					</div>
        </el-card> -->
		<el-card class="box-card m-b marT" shadow="never">
			<div slot="header" class="clearfix">
				<span>项目列表</span>
			</div>
			<div>
				<el-table
					:data="currentData"
					:header-cell-style="{background:'#eef1f6'}"
					style="width: 100%; margin-bottom: 20px"
					@sort-change="sortChange">
					<el-table-column prop="project_name" label="项目名" :sortable="'custom'"></el-table-column>
					<el-table-column prop="code_quality_check" label="代码质量检查" sortable></el-table-column>
					<el-table-column prop="code_style_check" label="代码规范检查" sortable></el-table-column>
					<el-table-column prop="avg_style_errors" label="代码规范检查错误数(平均)" sortable></el-table-column>
					<el-table-column prop="code_static_check" label="代码静态检查" sortable></el-table-column>
          <el-table-column prop="avg_static_errors" label="代码静态检查错误数(平均)" sortable></el-table-column>
					<el-table-column prop="avg_duplicate" label="代码重复行数(平均)" sortable></el-table-column>
					<el-table-column prop="git_log_check" label="Git log检查" sortable></el-table-column>
					<el-table-column prop="git_pass_rate" label="Git log检查通过率" sortable></el-table-column>
					<el-table-column prop="avg_complexity" label="圈复杂度(平均)" sortable></el-table-column>

				</el-table>
				<el-pagination
					@size-change="handleSizeChange"
					@current-change="handleCurrentChange"
					:current-page="currentPage"
					:page-sizes="[10, 15, 50, 100]"
					:page-size="currentSize"
					layout="total, sizes, prev, pager, next, jumper"
					:total="dataCount">
				</el-pagination>
			</div>
		</el-card>
    </div>
</template>

<script>
import { pagingData } from './utils.js';
import { getKpi } from '@/api/kpi'
import common from '@/components/devops/get_data';
import info_label from '@/components/devops/info_label.vue';
import info_label_compare from '@/components/devops/info_label_compare.vue';
import LabelGrid from '@/components/qa/Label.vue'
import { getHeader } from '@/app.config';
import { mapState } from 'vuex'
import http from '@/views/sys/axios'
import 'v-charts/lib/style.css';
import 'echarts/lib/component/dataZoom';
import tag from '@/components/tags/index'

export default {
	props: {
        params: Object
	},
	computed: {
		...mapState({
			standardKPI: state => state.standardKPI
		})
	},
	filters: {
		getprecent(num) {
			return (num*100).toFixed(2)
		}
	},
	components: {
		info_label,
		tag,
		LabelGrid,
		info_label_compare,
    },
    data () {
        this.dataZoom = [{
			type: 'slider',
			start: 0,
			end: 100
	    }];
        return {
			common,
			coverity_high_err_density: 0,
			coverity_medium_err_density: 0,
			coverity_low_err_density: 0,
			duplicateRate: 0,
			deptlableinfo: {
				rate: {
					label_header: 'Avg',
					label_hname: 'git log检查通过率',
					label_unit: '(%)',
					label_class: 'success'
				},
				quan: {
					label_header: 'Avg',
					label_hname: '圈复杂度',
					label_unit: '',
					label_class: 'success'
				}
			},
			passTrend: 'checkstyle指标',
			labelsData: {},
			kpi: {},
			checkstyle_data: {
				columns: ['update_date', 'checkstyle_pass_count', 'checkstyle_pass_rate'],
				rows: []
			},
			cpplintstyle_data: {
				columns: ['update_date', 'cpplint_count', 'cpplint_pass_count'],
				rows: []
			},
			clintstyle_data: {
				columns: ['update_date', 'clint_count', 'clint_pass_count'],
				rows: []
			},
			checkpatchstyle_data: {
				columns: ['update_date', 'checkpatch_pass_count', 'checkpatch_pass_rate'],
				rows: []
			},
			quality_trend_data: {
				columns: ['update_date', 'findbugs_pass_count', 'coverity_pass_count', 'pclint_pass_count', 'findbugs_pass_rate', 'coverity_pass_rate', 'pclint_pass_rate'],
				rows: []
			},			
			colors: ['#ed5565'],
			activeName: '0',
			activeName2: '0',
			activeNameError: '0',
			currentPage: 1,
			currentSize: 10,
			dataEmpty1: true,
			dataEmpty2: true,
			dataEmpty3: true,
			efficiencyData1: {
				columns: ['update_date', 'avg_clint_duration', 'avg_cpplint_duration', 'avg_checkpatch_duration', 'avg_checkstyle_duration'],
				rows: []
			},
			setEfficiency: {
				labelMap: {
					avg_clint_duration: 'clint检查效率',
					avg_cpplint_duration: 'cpplint检查效率',
					avg_checkpatch_duration: 'checkpatch检查效率',
					avg_checkstyle_duration: 'checkstyle检查效率',
					avg_pclint_duration: 'pclint检查效率',
					avg_coverity_duration: 'coverity检查效率',
					avg_findbugs_duration: 'findbugs检查效率',
					avg_sourcemonitor_duration: 'sourcemonitor检查效率',
					avg_simian_duration: 'simian检查效率'
				}
			},
			efficiencyData2: {
				columns: ['update_date', 'avg_pclint_duration', 'avg_coverity_duration', 'avg_findbugs_duration'],
				rows: []
			},
			efficiencyData3: {
				columns: ['update_date', 'avg_simian_duration', 'avg_sourcemonitor_duration'],
				rows: []
			},
            currentData: [],
            tableData: [],
            dataCount: 0,
			dataEmpty: true,
			colors: ['#ed5565'],
			topChartData1: {
                columns: ['project', 'avg_style_errors'],
                rows: []
			},
			topChartData2: {
                columns: ['project', 'avg_static_errors'],
                rows: []
			},
			topChartData3: {
                columns: ['project', 'avg_duplicate'],
                rows: []
			},
			topChartData4: {
                columns: ['project', 'git_pass_rate'],
                rows: []
			},
			topChartData5: {
                columns: ['project', 'avg_complexity'],
                rows: []
			},
			topExtend: {
                 series: {
                    barMaxWidth: 50,
                },
            },
			chartSettings: {
				labelMap: {
					avg_style_errors: '规范检查错误(个)',
					avg_static_errors: '静态检查错误(个)',
					avg_duplicate: '代码重复行数(行)',
					git_pass_rate: 'gitlog检查通过率(%)',
					avg_complexity: '圈复杂度'
				}
			},
			codeChartData: {
				columns: ['update_date', 'avg_static_errors'],
				rows: []
			},
			codeChartData2: {
				columns: [
					'update_date',
					'avg_style_errors'
				],
				rows: []
			},
			codeChartData3: {
				columns: [
					'update_date',
					'git_pass_rate'
				],
				rows: []
			},
			codeChartData4: {
				columns: [
					'update_date',
					'avg_duplicate'
				],
				rows: []
			},
			codeChartData5: {
				columns: [
					'update_date',
					'avg_complexity'
				],
				rows: []
			},
			codeChartSettings: {
				labelMap: {
					avg_static_errors: '代码静态检查错误数',
					avg_style_errors: '代码规范检查错误数',
					git_pass_rate: 'git log通过率(%)',
					avg_duplicate: '代码重复行数',
					avg_complexity: '圈复杂度',
					checkstyle_pass_count: 'checkstyle检查通过次数(次)',
					cpplint_pass_count: 'cpplint检查通过次数(次)',
					clint_pass_count: 'clint检查通过次数(次)',
					checkstyle_pass_rate: 'checkstyle检查通过率(%)',
					cpplint_pass_rate: 'cpplint检查通过率(%)',
					clint_pass_rate: 'clint检查通过率(%)',
					coverity_pass_count: 'coverity检查通过次数(次)',
					findbugs_pass_count: 'findbugs检查通过次数(次)',
					pclint_pass_count: 'pclint检查通过次数(次)',
					coverity_pass_rate: 'coverity检查通过率(%)',
					findbugs_pass_rate: 'findbugs检查通过率(%)',
					pclint_pass_rate: 'pclint检查通过率(%)',
					checkpatch_pass_count: 'checkpatch检查通过次数',
					checkpatch_pass_rate: 'checkpatch检查通过率(%)'
				}
			}
        }
	},
	methods: {
		getFix(data) {
				if (null == data || "undefined" == typeof(data) || "" == data) {
						return 0;
				} else {
						return data
				}
		},
		formatter_rate(row, column, cellValue, index) {
				var str = Number(cellValue*100).toFixed(2);
				str += "%";
				return str;
		},
		getTrend(departmentId, dates) {
			http.get(`/api/devops/dept/check/pass/trend?departmentId=${departmentId}&date=${dates}`)
			.then(res => {
				if(res.code == 200) {
					this.quality_trend_data.rows = res.quality_trend_data					
					let data = res.style_trend_data								
					this.checkstyle_data.rows = data
					this.cpplintstyle_data.rows = data
					this.clintstyle_data.rows = data
					this.checkpatchstyle_data.rows = data
					this.checkstyle_data.rows.forEach(val => {
						val.checkstyle_pass_rate = val.checkstyle_pass_rate*100
					})
					this.cpplintstyle_data.rows.forEach(val => {
						val.cpplint_pass_rate = val.cpplint_pass_rate*100
					})
					this.clintstyle_data.rows.forEach(val => {
						val.clint_pass_rate = val.clint_pass_rate*100
					})
					this.checkpatchstyle_data.rows.forEach(val => {
						val.checkpatch_pass_rate = val.checkpatch_pass_rate*100
					})
					
					this.quality_trend_data.rows.forEach(val => {
						val.coverity_pass_rate = val.coverity_pass_rate*100
						val.findbugs_pass_rate = val.findbugs_pass_rate*100
						val.pclint_pass_rate = val.pclint_pass_rate*100
					})
				}
			})
		},
		getPrecent(value) {
				let str = Number(value*100).toFixed(2)
				return str
		},
		getLabelKpi(type) {
			getKpi(type).then(res => {
				if (res.status == 200) {
						if (res.data.code === 200) {
							this.kpi = res.data.data
						}
				}
			})
		},
		init_datas: function(departmentId, dates) {
			this.get_compare_data(departmentId, dates);
			this.get_summary(departmentId, dates);
			this.getTrend(departmentId, dates);
			this.getRanking(departmentId, dates);
			this.getEffect(departmentId, dates)
			this.get_daily_data(departmentId, dates)
			this.getLabelKpi('CodeCheck')
        },
    formatSeconds(value) {
			if (isNaN(value)) {
				value = 0;
			}
			var theTime = parseInt(value); // 秒
			var theTime1 = 0; // 分
			var theTime2 = 0; // 小时
			var theTime3 = 0; // 天
			if (theTime > 60) {
				theTime1 = parseInt(theTime / 60);
				theTime = parseInt(theTime % 60);
				if (theTime1 > 60) {
					theTime2 = parseInt(theTime1 / 60);
					theTime1 = parseInt(theTime1 % 60);
					if (theTime2 > 24) {
						theTime3 = parseInt(theTime2 / 24);
						theTime2 = parseInt(theTime2 % 24);
					}
				}
			}
			var result = '' + parseInt(theTime) + '秒';
			if (theTime1 > 0) {
				result = '' + parseInt(theTime1) + '分' + result;
			}
			if (theTime2 > 0) {
				result = '' + parseInt(theTime2) + '时' + result;
			}
			if (theTime3 > 0) {
				result = '' + parseInt(theTime3) + '天' + result;
			}
			return result;
        },
        sortChange: function(val) {
			var key = val['prop'];
			var compare1 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return -1;
				} else if (val1 > val2) {
					return 1;
				} else {
					return 0;
				}
			};
			var compare2 = function(obj1, obj2) {
				var val1 = obj1[key];
				var val2 = obj2[key];
				if (val1 < val2) {
					return 1;
				} else if (val1 > val2) {
					return -1;
				} else {
					return 0;
				}
			};
			var arr = this.tableData;
			if (val['order'] === 'ascending') {
				this.currentData = pagingData(arr.sort(compare1), this.dataCount, this.currentPage, this.currentSize);
			} else if (val['order'] === 'descending') {
				this.currentData = pagingData(arr.sort(compare2), this.dataCount, this.currentPage, this.currentSize);
			} else {
				key = 'update_date';
				this.currentData = pagingData(arr.sort(compare2), this.dataCount, this.currentPage, this.currentSize);
			}
		},
		handleClick(tab, event) {
			console.log(tab, event)
		},
		handleSizeChange: function(size) {
			this.currentSize = size;
			this.currentData = pagingData(this.tableData, this.dataCount, this.currentPage, this.currentSize)
		},
		handleCurrentChange: function(page) {
			this.currentPage = page;
			this.currentData = pagingData(this.tableData, this.dataCount, this.currentPage, this.currentSize)
		},
		get_compare_data(departmentId, dates) {
			this.currentData = [];
			this.tableData = [];
			this.dataEmpty = true;
			var self = this
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/dept/compare?departmentId=' +
                departmentId + '&date=' + dates + '&page=codecheck',
				{headers: getHeader()})
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data.data;
							for (var i = 0; i < data.length; i++) {
								var tableDict = {
                                    project_name: data[i]['project'],
                                    avg_style_errors: data[i]['avg_style_errors'] + '个',
									avg_static_errors: data[i]['avg_static_errors'] + '个',
									avg_duplicate: data[i]['avg_duplicate'] + '行',
									git_pass_rate: self.getPrecent(data[i]['git_pass_rate']) + '%',
									code_quality_check: data[i]['code_quality_check'] + '次',
									code_static_check: data[i]['code_static_check'] + '次',
									code_style_check: data[i]['code_style_check'] + '次',
									git_log_check: data[i]['git_log_check'] + '次',
									avg_complexity: data[i]['avg_complexity']
								};
								self.tableData.push(tableDict);
							};
							self.dataCount = self.tableData.length;
							self.currentPage = 1;
							self.currentSize = 10;
							self.dataEmpty = false;
							if (self.dataCount === 0) {
								self.currentData = [];
								self.dataEmpty = true;
							} else {
								self.currentData = pagingData(self.tableData, self.dataCount, self.currentPage, self.currentSize)
							}
							// if(data) {
							// 	this.dataEmpty1 = false
							// 	this.dataEmpty2 = false
							// 	this.dataEmpty3 = false
							// } else {
							// 	this.dataEmpty1 = true
							// 	this.dataEmpty2 = true
							// 	this.dataEmpty3 = true
							// }
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
		getRanking(departmentId, dates) {
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/dept/check/ranking?departmentId=' +
                departmentId + '&date=' + dates,
				{headers: getHeader()})
				.then(res => {
					if (res.status == 200) {
						if (res.data.code === 200) {
							this.topChartData1.rows = res.data.style_errors_ranking.reverse()
							this.topChartData2.rows = res.data.static_errors_ranking.reverse()
							this.topChartData3.rows = res.data.duplicate_ranking.reverse()
							this.topChartData5.rows = res.data.complexity_ranking.reverse()
							if(res.data.git_pass_ranking.length) {
								let arr = res.data.git_pass_ranking
								arr.forEach(val => {
									if(val.git_pass_rate) {
										val.git_pass_rate = this.getPrecent(val.git_pass_rate)
									}
								})
								this.topChartData4.rows = arr.reverse()
							}

						}
					}
				}).catch(function(err) {
					console.log(err);
				});
		},
		get_daily_data(departmentId, dates) {
			var _self = this
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/dept/daily/summary?departmentId=' +
                departmentId + '&date=' + dates + '&page=codecheck',
				{headers: getHeader()})
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data.data;
							let change = data
							_self.codeChartData.rows = data
							_self.codeChartData2.rows = data
							change.forEach(val => {
								if(val.git_pass_rate) {
									val.git_pass_rate = _self.getPrecent(val.git_pass_rate)
								}
							})
							_self.codeChartData3.rows = change
							_self.codeChartData4.rows = data
							_self.codeChartData5.rows = data
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
		getEffect(departmentId, dates) {
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/dept/check/efficient?departmentId=' +
                departmentId + '&date=' + dates,
				{headers: getHeader()})
				.then(res => {
					if (res.status == 200) {
						if (res.data.code === 200) {
							this.efficiencyData1.rows = res.data.code_style_efficient
							this.efficiencyData2.rows = res.data.code_static_efficient
							this.efficiencyData3.rows = res.data.code_quality_efficient
						}
					}
				})

		},
		get_summary(departmentId, dates) {
			var _self = this
			_self.coverity_high_err_density = 0;
			_self.coverity_medium_err_density = 0;
			_self.coverity_low_err_density = 0;
			this.$axios.get(process.env.VUE_APP_KANBAN_HOST +
                '/api/devops/dept/summary?departmentId=' +
                departmentId + '&date=' + dates + '&page=codecheck',
				{headers: getHeader()})
				.then(function(response) {
					if (response.status == 200) {
						if (response.data.code === 200) {
							var data = response.data.data;
							_self.labelsData = data
							_self.coverity_high_err_density = _self.labelsData.static_count
								? _self.labelsData.coverity_high / _self.labelsData.static_count
								: 0;
							_self.coverity_medium_err_density = _self.labelsData.static_count
								? _self.labelsData.coverity_medium / _self.labelsData.static_count
								: 0;
							_self.coverity_low_err_density = _self.labelsData.static_count
								? _self.labelsData.coverity_low / _self.labelsData.static_count
								: 0;
						}
					}
				})
				.catch(function(err) {
					console.log(err);
				});
		},
		fomatFloat(src, pos) {
			return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
		},
		generate_label_params: function(val1, val2, dataType, dataTitle, label) {
			if (typeof val1 === 'undefined') {
				val1 = 0;
			}
			var labelParam;
			if (dataType === 'time') {
				var standardTime = val2[1] * 60;
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'reach' : 'down',
							difference:
								val1 > standardTime
									? ''
									: this.formatSeconds(standardTime - val1)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.formatSeconds(val1),
							status: val1 > standardTime ? 'up' : 'reach',
							difference:
								val1 > standardTime
									? this.formatSeconds(val1 - standardTime)
									: ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.formatSeconds(val1),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'percent') {
				if (val1) {
					console.log(val2[0])
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2) + '%',
							num: this.fomatFloat(val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) + '%' : '',
							num: this.fomatFloat(val1, 2)
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						status: 'reach',
						difference: '',
						num: this.fomatFloat(val1, 2)
					};
				}
				return labelParam;
			} else if (dataType === 'frequency') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else if (dataType === 'multiple') {
				if (val1) {
					if (val2[0]) {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'reach' : 'down',
							difference:
								val1 > val2[1] ? '' : this.fomatFloat(val2[1] - val1, 2)
						};
					} else {
						labelParam = {
							type: label,
							title: dataTitle,
							num: this.fomatFloat(val1, 2),
							status: val1 > val2[1] ? 'up' : 'reach',
							difference:
								val1 > val2[1] ? this.fomatFloat(val1 - val2[1], 2) : ''
						};
					}
				} else {
					labelParam = {
						type: label,
						title: dataTitle,
						num: this.fomatFloat(val1, 2),
						status: 'reach',
						difference: ''
					};
				}
				return labelParam;
			} else {
				labelParam = {
					type: label,
					title: dataTitle,
					num: this.fomatFloat(val1, 2),
					status: 'reach',
					difference: ''
				};
				return labelParam;
			}
		},
		formatSeconds(value) {
			if (isNaN(value)) {
				value = 0;
			}
			var theTime = parseInt(value); // 秒
			var theTime1 = 0; // 分
			var theTime2 = 0; // 小时
			var theTime3 = 0; // 天
			if (theTime > 60) {
				theTime1 = parseInt(theTime / 60);
				theTime = parseInt(theTime % 60);
				if (theTime1 > 60) {
					theTime2 = parseInt(theTime1 / 60);
					theTime1 = parseInt(theTime1 % 60);
					if (theTime2 > 24) {
						theTime3 = parseInt(theTime2 / 24);
						theTime2 = parseInt(theTime2 % 24);
					}
				}
			}
			var result = '' + parseInt(theTime) + '秒';
			if (theTime1 > 0) {
				result = '' + parseInt(theTime1) + '分' + result;
			}
			if (theTime2 > 0) {
				result = '' + parseInt(theTime2) + '时' + result;
			}
			if (theTime3 > 0) {
				result = '' + parseInt(theTime3) + '天' + result;
			}
			return result;
		}
	},
	watch: {
        params: {
			handler: function(val) {
				console.log('watchcode')
                const departmentId = val.departmentId === 'undefined' ? '' : val.departmentId;
                const dates = val.time === 'undefined' ? '' : val.time;
				this.init_datas(departmentId, dates);
			},
			deep: true
		},
		// activeName2(v) {
    //   this.$nextTick(() => {
		// 		this.$refs[`vline${v}`].echarts.resize()
		// 	})
		// },
		activeName(v) {
      this.$nextTick(() => {
				this.passTrend = 'checkstyle指标'
				this.$refs[`vline${v}`].echarts.resize()
				// this.$refs[`cline${v}`].echarts.resize()
				this.$refs[`lline${v}`].echarts.resize()
				if(v == 0) {
					this.$refs[`tline${v}`].echarts.resize()
				}
				if(v == 1) {
					this.$refs[`zline${v}`].echarts.resize()
				}
				if(v !== 3) {
					this.$refs[`jline${v}`].echarts.resize()
				}
			})
		},
		passTrend(val) {
			this.$nextTick(() => {
				if(val == 'checkstyle指标') {
					this.$refs[`tline0`].echarts.resize()
				} else if(val == 'cpplint指标') {
					this.$refs[`tline1`].echarts.resize()
				} else if(val == 'clint指标') {
					this.$refs[`tline2`].echarts.resize()
				} else {
					this.$refs[`tline3`].echarts.resize()
				}
			})
			
		}
		// activeNameError(val) {
		// 	this.$nextTick(() => {
		// 		this.$refs[`eline${val}`].echarts.resize()
		// 	})
		// }
	},
	// mounted() {
    //     const departmentId = this.params.departmentId === 'undefined' ? '' : this.params.departmentId;
    //     const dates = this.params.time === 'undefined' ? '' : this.params.time;
	// 	this.init_datas(departmentId, dates);
	// }
}
</script>

<style lang="scss" scoped>
	#wrapper >>>.container-wrapper .el-tabs--border-card{
		background: #fff
	}
	#wrapper .bgColor{
		background: #fff
	}
	.mart, .marT{
		margin-top: 20px;
	}
</style>
